home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 November / SGI Freeware 1999 November - Disc 1.iso / dist / fw_cvs.idb / usr / freeware / lib / cvs / contrib / sccs2rcs.z / sccs2rcs
Text File  |  1999-04-16  |  8KB  |  276 lines

  1. #! /sbin/csh -f
  2. #
  3. # Sccs2rcs is a script to convert an existing SCCS
  4. # history into an RCS history without losing any of
  5. # the information contained therein.
  6. # It has been tested under the following OS's:
  7. #     SunOS 3.5, 4.0.3, 4.1
  8. #     Ultrix-32 2.0, 3.1
  9. #
  10. # Things to note:
  11. #   + It will NOT delete or alter your ./SCCS history under any circumstances.
  12. #
  13. #   + Run in a directory where ./SCCS exists and where you can
  14. #       create ./RCS
  15. #
  16. #   + /usr/local/bin is put in front of the default path.
  17. #     (SCCS under Ultrix is set-uid sccs, bad bad bad, so
  18. #     /usr/local/bin/sccs here fixes that)
  19. #
  20. #   + Date, time, author, comments, branches, are all preserved.
  21. #
  22. #   + If a command fails somewhere in the middle, it bombs with
  23. #     a message -- remove what it's done so far and try again.
  24. #         "rm -rf RCS; sccs unedit `sccs tell`; sccs clean"
  25. #     There is no recovery and exit is far from graceful.
  26. #     If a particular module is hanging you up, consider
  27. #     doing it separately; move it from the current area so that
  28. #     the next run will have a better chance or working.
  29. #     Also (for the brave only) you might consider hacking
  30. #     the s-file for simpler problems:  I've successfully changed
  31. #     the date of a delta to be in sync, then run "sccs admin -z"
  32. #     on the thing.
  33. #
  34. #   + After everything finishes, ./SCCS will be moved to ./old-SCCS.
  35. #
  36. # This file may be copied, processed, hacked, mutilated, and
  37. # even destroyed as long as you don't tell anyone you wrote it.
  38. #
  39. # Ken Cox
  40. # Viewlogic Systems, Inc.
  41. # kenstir@viewlogic.com
  42. # ...!harvard!cg-atla!viewlog!kenstir
  43. #
  44. # Various hacks made by Brian Berliner before inclusion in CVS contrib area.
  45.  
  46.  
  47. #we'll assume the user set up the path correctly
  48. # for the Pmax, /usr/ucb/sccs is suid sccs, what a pain
  49. #   /usr/local/bin/sccs should override /usr/ucb/sccs there
  50. set path = (/usr/local/bin $path)
  51.  
  52.  
  53. ############################################################
  54. # Error checking
  55. #
  56. if (! -w .) then
  57.     echo "Error: ./ not writeable by you."
  58.     exit 1
  59. endif
  60. if (! -d SCCS) then
  61.     echo "Error: ./SCCS directory not found."
  62.     exit 1
  63. endif
  64. set edits = (`sccs tell`)
  65. if ($#edits) then
  66.     echo "Error: $#edits file(s) out for edit...clean up before converting."
  67.     exit 1
  68. endif
  69. if (-d RCS) then
  70.     echo "Warning: RCS directory exists"
  71.     if (`ls -a RCS | wc -l` > 2) then
  72.         echo "Error: RCS directory not empty
  73.         exit 1
  74.     endif
  75. else
  76.     mkdir RCS
  77. endif
  78.  
  79. sccs clean
  80.  
  81. set logfile = /tmp/sccs2rcs_$$_log
  82. rm -f $logfile
  83. set tmpfile = /tmp/sccs2rcs_$$_tmp
  84. rm -f $tmpfile
  85. set emptyfile = /tmp/sccs2rcs_$$_empty
  86. echo -n "" > $emptyfile
  87. set initialfile = /tmp/sccs2rcs_$$_init
  88. echo "Initial revision" > $initialfile
  89. set sedfile = /tmp/sccs2rcs_$$_sed
  90. rm -f $sedfile
  91. set revfile = /tmp/sccs2rcs_$$_rev
  92. rm -f $revfile
  93.  
  94. # the quotes surround the dollar signs to fool RCS when I check in this script
  95. set sccs_keywords = (\
  96.     '%W%[     ]*%G%'\
  97.     '%W%[     ]*%E%'\
  98.     '%W%'\
  99.     '%Z%%M%[     ]*%I%[     ]*%G%'\
  100.     '%Z%%M%[     ]*%I%[     ]*%E%'\
  101.     '%M%[     ]*%I%[     ]*%G%'\
  102.     '%M%[     ]*%I%[     ]*%E%'\
  103.     '%M%'\
  104.     '%I%'\
  105.     '%G%'\
  106.     '%E%'\
  107.     '%U%')
  108. set rcs_keywords = (\
  109.     '$'Id'$'\
  110.     '$'Id'$'\
  111.     '$'Id'$'\
  112.     '$'SunId'$'\
  113.     '$'SunId'$'\
  114.     '$'Id'$'\
  115.     '$'Id'$'\
  116.     '$'RCSfile'$'\
  117.     '$'Revision'$'\
  118.     '$'Date'$'\
  119.     '$'Date'$'\
  120.     '')
  121.  
  122.  
  123. ############################################################
  124. # Get some answers from user
  125. #
  126. echo ""
  127. echo "Do you want to be prompted for a description of each"
  128. echo "file as it is checked in to RCS initially?"
  129. echo -n "(y=prompt for description, n=null description) [y] ?"
  130. set ans = $<
  131. if ((_$ans == _) || (_$ans == _y) || (_$ans == _Y)) then
  132.     set nodesc = 0
  133. else
  134.     set nodesc = 1
  135. endif
  136. echo ""
  137. echo "The default keyword substitutions are as follows and are"
  138. echo "applied in the order specified:"
  139. set i = 1
  140. while ($i <= $#sccs_keywords)
  141. #    echo '    '\"$sccs_keywords[$i]\"'    ==>    '\"$rcs_keywords[$i]\"
  142.     echo "    $sccs_keywords[$i]    ==>    $rcs_keywords[$i]"
  143.     @ i = $i + 1
  144. end
  145. echo ""
  146. echo -n "Do you want to change them [n] ?"
  147. set ans = $<
  148. if ((_$ans != _) && (_$ans != _n) && (_$ans != _N)) then
  149.     echo "You can't always get what you want."
  150.     echo "Edit this script file and change the variables:"
  151.     echo '    $sccs_keywords'
  152.     echo '    $rcs_keywords'
  153. else
  154.     echo "good idea."
  155. endif
  156.  
  157. # create the sed script
  158. set i = 1
  159. while ($i <= $#sccs_keywords)
  160.     echo "s,$sccs_keywords[$i],$rcs_keywords[$i],g" >> $sedfile
  161.     @ i = $i + 1
  162. end
  163.  
  164. onintr ERROR
  165.  
  166. ############################################################
  167. # Loop over every s-file in SCCS dir
  168. #
  169. foreach sfile (SCCS/s.*)
  170.     # get rid of the "s." at the beginning of the name
  171.     set file = `echo $sfile:t | sed -e "s/^..//"`
  172.  
  173.     # work on each rev of that file in ascending order
  174.     set firsttime = 1
  175.     sccs prs $file | grep "^D " | awk '{print $2}' | sed -e 's/\./ /g' | sort -n -u +0 +1 +2 +3 +4 +5 +6 +7 +8 | sed -e 's/ /./g' > $revfile
  176.     foreach rev (`cat $revfile`)
  177.         if ($status != 0) goto ERROR
  178.  
  179.         # get file into current dir and get stats
  180.         set date = `sccs prs -r$rev $file | grep "^D " | awk '{printf("19%s %s", $3, $4); exit}'`
  181.         set author = `sccs prs -r$rev $file | grep "^D " | awk '{print $5; exit}'`
  182.         echo ""
  183.         echo "==> file $file, rev=$rev, date=$date, author=$author"
  184.         sccs edit -r$rev $file >>& $logfile
  185.         if ($status != 0) goto ERROR
  186.         echo checked out of SCCS
  187.  
  188.         # add RCS keywords in place of SCCS keywords
  189.         sed -f $sedfile $file > $tmpfile
  190.         if ($status != 0) goto ERROR
  191.         echo performed keyword substitutions
  192.         cp $tmpfile $file
  193.  
  194.         # check file into RCS
  195.         if ($firsttime) then
  196.             set firsttime = 0
  197.             if ($nodesc) then
  198.         echo about to do ci
  199.                 echo ci -f -r$rev -d"$date" -w$author -t$emptyfile $file 
  200.                 ci -f -r$rev -d"$date" -w$author -t$emptyfile $file < $initialfile >>& $logfile
  201.                 if ($status != 0) goto ERROR
  202.                 echo initial rev checked into RCS without description
  203.             else
  204.                 echo ""
  205.                 echo Enter a brief description of the file $file \(end w/ Ctrl-D\):
  206.                 cat > $tmpfile
  207.                 ci -f -r$rev -d"$date" -w$author -t$tmpfile $file < $initialfile >>& $logfile
  208.                 if ($status != 0) goto ERROR
  209.                 echo initial rev checked into RCS
  210.             endif
  211.         else
  212.             # get RCS lock
  213.         set lckrev = `echo $rev | sed -e 's/\.[0-9]*$//'`
  214.         if ("$lckrev" =~ [0-9]*.*) then
  215.         # need to lock the brach -- it is OK if the lock fails
  216.         rcs -l$lckrev $file >>& $logfile
  217.         else
  218.         # need to lock the trunk -- must succeed
  219.                 rcs -l $file >>& $logfile
  220.                 if ($status != 0) goto ERROR
  221.         endif
  222.             echo got lock
  223.             sccs prs -r$rev $file | grep "." > $tmpfile
  224.             # it's OK if grep fails here and gives status == 1
  225.             # put the delta message in $tmpfile
  226.             ed $tmpfile >>& $logfile <<EOF
  227. /COMMENTS
  228. 1,.d
  229. w
  230. q
  231. EOF
  232.             ci -f -r$rev -d"$date" -w$author $file < $tmpfile >>& $logfile
  233.             if ($status != 0) goto ERROR
  234.             echo checked into RCS
  235.         endif
  236.         sccs unedit $file >>& $logfile
  237.         if ($status != 0) goto ERROR
  238.     end
  239.     rm -f $file
  240. end
  241.  
  242.  
  243. ############################################################
  244. # Clean up
  245. #
  246. echo cleaning up...
  247. mv SCCS old-SCCS
  248. rm -f $tmpfile $emptyfile $initialfile $sedfile
  249. echo ===================================================
  250. echo "       Conversion Completed Successfully"
  251. echo ""
  252. echo "         SCCS history now in old-SCCS/"
  253. echo ===================================================
  254. set exitval = 0
  255. goto cleanup
  256.  
  257. ERROR:
  258. foreach f (`sccs tell`)
  259.     sccs unedit $f
  260. end
  261. echo ""
  262. echo ""
  263. echo Danger\!  Danger\!
  264. echo Some command exited with a non-zero exit status.
  265. echo Log file exists in $logfile.
  266. echo ""
  267. echo Incomplete history in ./RCS -- remove it
  268. echo Original unchanged history in ./SCCS
  269. set exitval = 1
  270.  
  271. cleanup:
  272. # leave log file
  273. rm -f $tmpfile $emptyfile $initialfile $sedfile $revfile
  274.  
  275. exit $exitval
  276.